package com.duolia.update;

import java.io.IOException;

import android.text.TextUtils;

import com.duolia.bless.utils.L;
import com.duolia.dson.Dson;
import com.duolia.dson.JsonAdapter;

/**
 * Parse the UpdateInfo from the json string
 * <p/>
 */
public class UpdateJsonParser extends AbstractParser {

    /**
     * Parse the UpdateInfo form the string
     *
     * @param content
     * @return UpdateInfo
     * @throws UpdateException
     */
    @Override
    public UpdateInfo parse(String content) throws UpdateException {
        UpdateInfo info = null;

        if (TextUtils.isEmpty(content)) {
            throw new UpdateException(UpdateException.PARSE_ERROR);
        }

        Dson dson = new Dson.Builder().build();
        JsonAdapter<UpdateInfoRes> adapter = dson.adapter(UpdateInfoRes.class);
        try {
			info = adapter.fromJson(content).getUpdateInfo();
		} catch (IOException e) {
			L.e("IOException", e.getLocalizedMessage());
		}
        return info;
    }
}